#include "screen.h"
//Prototype functions
void Screen::blit(){
	return;
};

Screen::Screen(){
	type=SCR_;
};

/*Screen::Screen(Python* python){
};
*/
Screen::~Screen(){
};

Input* Screen::get_input(){
	return NULL;
};

//Controlling the console output
void Screen_console::blit(){
	for(list <Widget*> ::iterator it= widgets.begin(); it != widgets.end(); it++){
    draw_widget(*it);
	}
	console->blit();
};

Screen_console::Screen_console(){
	type=SCR_CONSOLE;
	console=new Console();
};

Screen_console::~Screen_console(){
	delete console;
};

Widget* Screen_console::add_widget(Widget_unit widget_unit){
	Widget* widget=new Widget_unit(widget_unit);
	widgets.push_front(widget);
	return widget;
};

Widget* Screen_console::add_widget(Widget_building widget_building){
	Widget* widget=new Widget_building(widget_building);
	widgets.push_back(widget);
	return widget;
};

void Screen_console::delete_widget(Widget* widget){
	widgets.remove(widget);
};

Widget* Screen_console::get_widget(Unit* unit){
	Widget* widget=new Widget_unit();
	return widget;
};

Widget* Screen_console::get_widget(Building* building){
	Widget* widget=new Widget_building();
	return widget;
};

bool Screen_console::draw_msgbox(string text){
	console->print_string(text, 20, 20, PAIR_ALLY);
	console->print_string("OKěščřžýáíé",r 25, 21, PAIR_SELF);
	return (console->get_key()==10);
}

Input* Screen_console::get_input(){
	int key= (unsigned char)console->get_key();
	if (key>0){
		return new Input_key(key, false, false, false);
	}
	else{
		return NULL;
	}
};

void Screen_console::draw_widget(Widget* widget){
	switch (widget->type){
		case WID_UNIT:
			console->print_char(((Widget_unit*)widget)->name, widget->y, widget->x, PAIR_SELF);
			break;
		case WID_BUILDING:
			console->print_string(((Widget_building*)widget)->name, widget->x, widget->y, PAIR_SELF);
			break;
	}
};
